<template>
    <div>
        <el-tabs v-model="params.functionType" @tab-click="handleClick">
            <el-tab-pane label="平台资讯" name="0">
                <!-- <el-form :inline="true" :model="params" ref="params" class="demo-form-inline" size="small"  @submit.native.prevent>
                    <el-form-item label="栏目名称">
                        <el-input  @keyup.enter.native="onSubmit" v-model="params.cloumnName" placeholder="栏目名称" ></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">查询</el-button>
                        <el-button @click="onReset">重置</el-button>
                        <el-button type="primary" @click="handleSub">新增政策资讯订阅</el-button>
                    </el-form-item>
                </el-form> -->
            </el-tab-pane>
			<el-tab-pane label="机构资讯" name="1">
			</el-tab-pane>
			<el-tab-pane label="专家资讯" name="2">
			</el-tab-pane>
            <!-- <el-tab-pane label="服务栏目订阅" name="2">
                <MySub ref="myContent" />
            </el-tab-pane> -->
        </el-tabs>
		
		<el-form :inline="true" :model="params" ref="params" class="demo-form-inline sarchForm" size="small"
			@submit.native.prevent>
			<el-form-item label="资讯名称">
				<el-input @keyup.enter.native="handleSubmit" v-model="params.zxName"
					placeholder="资讯名称"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="handleSubmit">查询</el-button>
				<el-button @click="handleReset">重置</el-button>
			</el-form-item>
			<el-form-item>
				<!-- <el-button size="small" @click="batchTransfer()" plain type="success">批量转移</el-button> -->
			</el-form-item>
		</el-form>
		
		<el-table v-loading="loading" :data="newData" style="width: 100%" :header-cell-style="{ background: '#f0f2f5' }">
		    <el-table-column label="序号" width="48" type="index"></el-table-column>
		    <el-table-column prop="name" label="资讯名称" show-overflow-tooltip>
				<template slot-scope="scope">
					<span class="nameHover" @click="handleName(scope.row.id)">{{scope.row.name}}</span>
				</template>
		    </el-table-column>
			<el-table-column prop="informationType" label="资讯类别" show-overflow-tooltip>
				<template slot-scope="scope">
					<el-tag v-if="scope.row.informationType === '0'">平台资讯</el-tag>
					<el-tag v-if="scope.row.informationType === '1'">机构资讯</el-tag>
					<el-tag v-if="scope.row.informationType === '2'">专家资讯</el-tag>
				</template>
			</el-table-column>
		    <el-table-column prop="createTime" label="创建时间">
		    </el-table-column>
			
		    <el-table-column fixed="right" label="操作" width="120">
		        <template slot-scope="scope">
		            <!-- <el-button @click="hanldeDelete(scope.row.id)" type="text" size="small">查看</el-button> -->
					<el-button @click="hanldeDetail(scope.row)" type="text" size="small">查看</el-button>
		        </template>
		    </el-table-column>
		</el-table>
		<!-- 分页 -->
		<div class="poolPage">
		    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
		        :current-page="params.page" :page-sizes="[10, 20, 30]" :page-size="params.pageSize"
		        layout="total, sizes, prev, pager, next, jumper" :total="total">
		    </el-pagination>
		</div>
		
        <!-- <SubscribeDialog @getNewList="getNewList" ref="subDialog" /> -->
		<commentDialog ref="commentDialog"></commentDialog>
    </div>
</template>
<script>
// import { myNews, getNewDelete } from "@/request/api/subscribe"
// import SubscribeDialog from "./subscribeDialog.vue"
// import MySub from "./mySub.vue";
import commentDialog from "./commentDialog.vue";
import {
		industryNewMyCommentList
	} from "@/request/api/industryNew";
export default {
    components: {
        // MySub,
        // SubscribeDialog
		commentDialog
    },
    data() {
        return {
            activeName: '1',
            params: {
				zxName:"",
                page: 1,
                pageSize: 10,
                functionType: 0,
				createBy:""
            },
            total:0,
            newData: [],
			
			loading:false
        }
    },
    created() {
		if (window.sessionStorage.getItem("userInfo") !== null) {
		  let userInfo = JSON.parse(window.sessionStorage.getItem("userInfo"));
		  this.params.createBy = userInfo.id
		}
        this.getNewList()
    },
    methods: {
		// 资讯详情
		handleName(id){
			let url = this.$router.resolve({
				name: "industryNewDetail",
				query: {
					id,
					menuIndex: this.params.functionType
				},
			});
			window.open(url.href, "_blank");
		},
		// 查询
		handleSubmit() {
			this.params.page = 1;
			this.getNewList();
		},
		// 重置
		handleReset() {
			this.params.page = 1;
			this.params.zxName = null;
			this.getNewList();
		},
		// 点击标签
        handleClick(tab) {
            // if (tab.name === '1') {
                this.getNewList()
            // } else if (tab.name === '2') {
            //     this.$refs.myContent.open()
            // }
        },
        // 获取列表
        getNewList() {
			this.loading = true
			this.newData = []
            industryNewMyCommentList(this.params).then(res => {
				this.loading = false
                if (res.data.code === 200) {
                    this.newData = res.data.result.items
                    this.total = res.data.result.total
                }
            })
        },
        // 查询
        onSubmit() {
            this.params.page = 1
            this.getNewList()
        },
        // 重置
        onReset() {
            this.params.page = 1
            this.params.cloumnName = null
            this.getNewList()
        },
        // 删除
        hanldeDelete(id) {
            this.$confirm("确定取消订阅该信息吗?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                getNewDelete(id).then((res) => {
                    if (res.data.code === 200) {
                        this.$message({
                            message: res.data.message,
                            type: "success",
                        });
                        this.getNewList()
                    } else {
                        this.$message.error(res.data.message);
                    }
                });
            })
        },
		// 查看
		hanldeDetail(item){
			this.$refs.commentDialog.open(item.id,item.name)
		},
        // 订阅
        handleSub() {
            this.$refs.subDialog.open()
        },
        handleSizeChange(val) {
            this.params.pageSize = val;
            this.params.page = 1;
            this.getNewList();
        },
        handleCurrentChange(val) {
            this.params.page = val;
            this.getNewList();
        },

    }
}
</script>
<style lang="less" scoped>

.poolPage{
    text-align: right;
    margin-top:15px;
}
.nameHover:hover{
	cursor: pointer;
	color: #409EFF;
}
</style>


